#ifndef JOBSHOPSCHEDULINGENVIRONMENT_H_
#define JOBSHOPSCHEDULINGENVIRONMENT_H_

#include <vector>
#include <string>
#include "../Environment.h"
#include "../../Solution/PermutationEncoded/PermutationEncodedSolution.h"

struct JSSTask {
    int machineRequired;
    long timeRequired;
};

struct JSSJob {
    string jobName;
    vector<JSSTask> tasks;
};

struct JSSMachine {
    string machineName;
};

struct JSSTaskReport {
    long startTime;
    long stopTime;
};

struct JSSJobReport {
    vector<JSSTaskReport> taskReports; 
};

template <typename T=PermutationEncodedSolution> class JobShopSchedulingEnvironment : public Environment
{
    public:
        JobShopSchedulingEnvironment();
        virtual ~JobShopSchedulingEnvironment();
        Crossover* configureCrossover();                           /**< Returns a crossover usable by this environment       */        
        double evaluateFitness(Solution*);                         /**< Evaluates the fitness of the given solution          */
        void generateRandomPopulation(vector<Solution*> &, unsigned int);   /**< Fills the provided vector with a random population   */
        string formatSolution(Solution* solution);                 /**< Outputs the solution with extra information          */
        void configure();                                          /**< Configures the environment                           */
        void configure(string);                            /**< Configures the environment from a file               */
        
        static string getName();
        static Environment* getEnvironment();                      /**< Static environment factory for knapsack environments */
    
    private:
        void populateRandomly();
        void populateFromFile();    
        vector<JSSJobReport> prepareReport(Solution*);
        int decodeTaskIDToJobNum(int);
        int decodeTaskIDToTaskNum(int);
        int encodeJobNumTaskNumToTaskID(int jobNum, int taskNum);
        void populateSolution(Solution*);
        vector<JSSJob> jobs;
        vector<JSSMachine> machines;
};

#endif /*JOBSHOPSCHEDULINGENVIRONMENT_H_*/
